package com.nbsaas.boot.contoller;

import com.nbsaas.boot.app.api.apis.AppUserRoleApi;
import com.nbsaas.boot.app.api.domain.request.AppUserRoleRequest;
import com.nbsaas.boot.app.api.domain.request.AppUserRoleSearch;
import com.nbsaas.boot.app.api.domain.response.AppUserRoleResponse;
import com.nbsaas.boot.app.api.domain.simple.AppUserRoleSimple;
import com.nbsaas.boot.app.ext.apis.AppUserRoleExtApi;
import com.nbsaas.boot.app.ext.domain.request.UpdateRoleRequest;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 *  对外控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/appUserRole")
public class AppUserRoleController {


    @Resource
    private AppUserRoleApi appUserRoleApi;



    @Resource
    private AppUserRoleExtApi appUserRoleExtApi;

    @RequiresPermissions("appRole")
    @PostMapping("/updateRoleAll")
    public ResponseObject<?> updateRoleAll(@RequestBody UpdateRoleRequest request) {
        return appUserRoleExtApi.updateRoleAll(request);
    }

    /**
     * 更新某个用户的角色
     *
     * @param updateRoleRequest
     * @return
     */
    @RequiresPermissions("appRole")
    @PostMapping("/updateRole")
    public ResponseObject<?> updateRole(@RequestBody UpdateRoleRequest updateRoleRequest) {
        return appUserRoleExtApi.updateRole(updateRoleRequest);
    }

    @RequiresPermissions("appUserRole")
    @RequestMapping("/search")
    public PageResponse<AppUserRoleSimple> search(@RequestBody AppUserRoleSearch request) {
        return appUserRoleApi.search(request);
    }

    @RequiresPermissions("appUserRole")
    @RequestMapping("/list")
    public ListResponse<AppUserRoleSimple> list(@RequestBody AppUserRoleSearch request) {
        return appUserRoleApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("appUserRole")
    @CreateData
    @RequestMapping("/create")
    public ResponseObject<AppUserRoleResponse> create(@RequestBody @Validated(AddOperator.class) AppUserRoleRequest request) {
        return appUserRoleExtApi.create(request);
    }

    @RequiresPermissions("appUserRole")
    @UpdateData
    @RequestMapping("/update")
    public ResponseObject<AppUserRoleResponse> update(@RequestBody @Validated(UpdateOperator.class) AppUserRoleRequest request) {
        return appUserRoleApi.update(request);
    }

    @RequiresPermissions("appUserRole")
    @RequestMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) AppUserRoleRequest request) {
        return appUserRoleApi.delete(request);
    }

    @RequiresPermissions("appUserRole")
    @RequestMapping("/view")
    public ResponseObject<AppUserRoleResponse> view(@RequestBody @Validated(ViewOperator.class) AppUserRoleRequest request) {
        return appUserRoleApi.view(request);
    }
}